package net.wesley.android.city;

import android.os.Handler;
import android.os.Message;

import net.wesley.android.City;
import net.yebaihe.sdk.HttpConnection;

public class ZhengZhou extends City {

	private Handler request1handler=new Handler(){
		public void handleMessage(Message message){
			String[] rows;
			boolean firstrow;
			String retvalue;
			switch (message.what){
			case HttpConnection.DID_ERROR://DID ERROR
				callback.onComplete(-1, "");
				break;
			case HttpConnection.DID_SUCCEED://DID SUCC
				String str=(String)message.obj;
				
				if (str.trim().equals("1")){
					callback.onComplete(-10031, "ret:请核实输入信息是否正确。");
					return;
				}	
				else if (str.trim().equals("2")){
					callback.onComplete(-10032, "ret:交警网返回以下错误：系统错误。");
					return;
				}
				
				if (str.indexOf("<table>")<=0){
					callback.onComplete(0, "");
				}
				rows=str.split("<table>");
				firstrow=true;
				retvalue="";
				for (int i=0;i<rows.length;i++){
					if (firstrow){
						firstrow=false;
						continue;
					}
					String row=rows[i];
					String[] cols = row.split("<td");
					String shijian = cols[2].split(">")[1].split("<")[0];
					String didian = cols[3].split(">")[1].split("<")[0];
					String code = cols[4].split(">")[1].split("<")[0];
					retvalue+=String.format("shijian:%s\ndidian:%s\ncode:%s\n\n" ,shijian,didian,code);
				}
				callback.onComplete(rows.length-1, retvalue);
				break;
			}
		}
	};

	public void requestParamsFinish(String[] values) {
		new HttpConnection(ctx,request1handler,"GBK").post("http://www.zzcgs.com.cn/peccancy/veh_search_ajax.jsp", 
				String.format("hphm=%s&vin=%s&hpzl=02&type=2",
						chepai.substring(2),values[0].toUpperCase()));
	}

	@Override
	public boolean match(String chepai) {
		return chepai.startsWith("豫A");
	}

	@Override
	public String[] paramDesc() {
		String[] s={"车辆识别代码"};
		return s;
	}

}
